{extend name="public:base"}
{block name="main"}
<div class="demoTable">
  <form class="layui-form" action="">
  <div class="layui-input-inline">
    <a  href="javascript:LayerOpen('{:Url('cateadd',array('cateid'=>input('pid')))}');" class="layui-btn layui-btn-normal" data-type="reload" lay-filter="cateadd" lay-submit>添加分类</a>
  </div>
  <div class="layui-input-inline">
    <a  href="javascript:LayerOpen('{:Url('catetree')}');" class="layui-btn layui-btn-normal" data-type="reload" lay-filter="cateadd" lay-submit>查看分类</a>
  </div>

</div>
<table class="layui-table" lay-data="{height:650,url:location.href,where:{pid:''}, id:'table', page:false}" lay-filter="table" id="table" lay-size="lg">
  <thead>
    <tr>
      <th lay-data="{field:'cateid',width:65}">ID</th>
      <th lay-data="{field:'catepx',width:65}">排序</th>
      <th lay-data="{field:'catethumb',templet:'#thumb',width:75}">缩略图</th>
      <th lay-data="{field:'catename'}">分类名称</th>
      <th lay-data="{field:'url',templet:'#link'}">跳转连接</th>
      <th lay-data="{field:'modelname'}">模型</th>
      <th lay-data="{field:'isnav',templet:'#nav',width:105}">导航</th>
      <th lay-data="{field:'status',templet:'#status',width:105}">状态</th>
      <th lay-data="{field:'addtime'}">添加时间</th>
      <th lay-data="{fixed: 'right',  toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>

<!-- <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="child">子菜单</a> -->

<script type="text/html" id="barDemo">
  
  <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
   
  <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
  {{#  if(d.catetype == '单页面'){ }}
      <a class="layui-btn layui-btn-sm" lay-event="editpage">页面编辑</a>
  {{#  } }} 

</script>

<script>
layui.use(['table','laydate','form'], function(){
  
  table = layui.table;
  laydate = layui.laydate;
  form = layui.form;

  table.on('tool(table)', function(obj){

    var data = obj.data;

    if(obj.event === 'del'){

      admin.delete({ url : 'catedel', obj :obj});
      
    } else if(obj.event === 'edit'){

        LayerOpen('cateedit/cateid/'+data.cateid);

    } else if(obj.event === 'editpage'){

        location.href="pageinfo/cateid/"+data.cateid;

    } else if(obj.event === 'child'){

      location.href="catelist/pid/"+data.cateid;

    }/* else if(obj.event === 'content'){
 			
    	console.log(obj.data.catetype);

   		if(obj.data.catetype=='单页面'){

   			location.href="/admin.php/cate/content/cateid/"+data.cateid;

   		}else if(obj.data.catetype=='文章模型'){

   			location.href="/admin.php/cate/newslist/cateid/"+data.cateid;

   		}
       
    }else if(obj.event === 'addcontent'){
    	location.href= "/admin.php/cate/content/cateid/"+data.cateid;
    }*/
    
  });

  admin.switch({ url : 'cateup', elem : 'status'});
  admin.switch({ url : 'cateup', elem : 'isnav'});

  //下拉选择
  form.on('select(select)', function(data){

    table.reload('table', {
      url: location.href
      ,where: {
         pid:data.value
      } 
      
    });

  });      
    

});
</script>

<script type="text/html" id="link">
  {{#  if(d.url != '' && typeof(d.url) != 'undefined'){ }}
     <a href="{{d.url}}" class="layui-table-link" target="_blank">{{d.url}}</a>
  {{#  } }}
</script>
<script type="text/html" id="thumb">
  <img src='{{d.src}}' >
</script>
<script type="text/html" id="status">

    <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" lay-url='cateup' value="{{d.cateid}}"  {{#  if(d.status == 1){ }} checked {{#  } }}>
  
</script>
<script type="text/html" id="nav">
  
    <input type="checkbox" name="isnav" lay-skin="switch" lay-text="显示|隐藏" lay-filter="isnav" lay-url='cateup' value="{{d.cateid}}" {{#  if(d.isnav == 1){ }} checked {{#  } }}>
  
</script>



{/block}